package Exercise1;

/**
 * ClassName:ThreadTest
 * Package:Exercise1
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2022/11/29 - 11:24
 * @Version:v1.0
 */
public class ThreadTest {
    public static void main(String[] args){
        Mythread m = new Mythread();
        Thread t = new Thread(m);
        t.setName("分线程");
        t.start();
        Thread.currentThread().setName("主线程");
        for (int i = 0; i < 100; i++) {
            if(i%2==0)
            {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}

class Mythread implements Runnable
{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if(i%2==0)
            {
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}